[% setvar title C<tr///> in array context should return a histogram %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p><code>tr///</code> in array context should return a histogram</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Simon Cozens &lt;<a href='mailto:simon@brecon.co.uk'>simon@brecon.co.uk</a>&gt;
  Date: 24 Sep 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 283
  Version: 1
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p><code>tr///</code> in array context should return a histogram explaining the
number of matches for each letter in the pattern.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>This has been on the Perl 5 to-do list for ages and ages. The idea is
that when you're transliterating a bunch of things, you want to know
how many of each of them matched in your original string.</p>
<p>For instance, while <code>tr/x//</code> will count the x's, <code>tr/xy//</code> will count
both x's and y's - you don't know how many of each. So, the proposal is
that <code>tr</code> in the array context should return a hash, like this:</p>
<pre>    (%foo) = &quot;xyzzy&quot; =~ tr/xyz//

    # %foo is ( x =&gt; 1, y =&gt; 2, z =&gt; 3);</pre>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>I posted a patch to Perl 5.6 to do this some time back; it's a very
simple matter of constructing the hash and incrementing the values every
time you do a transliteration of a character. Of course, since we don't
know what Perl 6's transliteration operator's going to look like, it's
hard to know how to implement an extension to it...</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>None.</p>
</div>
